<template>
  <view>
    <view class="empty-cart" v-if="getCartList.length === 0">
      <image
        class="empty-img"
        src="/static/cart_empty@2x.png"
        mode="scaleToFill"
      />
      <text class="tip-text">空空如也~</text>
    </view>
    <view class="cart-container" v-else>
      <my-address></my-address>
      <view class="cart-title">
        <uni-icons type="shop" :size="17" />
        <text class="cart-title-text">小黑自营</text>
      </view>
      <uni-swipe-action>
        <uni-swipe-action-item
          :right-options="options"
          @click="delGoods(item)"
          v-for="item in getCartList"
          :key="item.goods_id"
        >
          <my-goods
            :goods="item"
            :isShowRadio="true"
            :isShowNumber="true"
            @radio-change="radioChange"
            @number-change="numberChange"
          />
        </uni-swipe-action-item>
      </uni-swipe-action>
      <my-settle></my-settle>
    </view>
  </view>
</template>

<script>
import tabBarMixin from '@/mixins/tabBar-setBadge.js'
import { mapGetters, mapMutations } from 'vuex'
export default {
  mixins: [tabBarMixin],
  computed: {
    ...mapGetters('cart', ['getCartList'])
  },
  data () {
    return {
      options: [
        {
          text: '删除',
          style: {
            backgroundColor: '#c00000'
          }
        }
      ]
    }
  },
  methods: {
    ...mapMutations('cart', ['changeRadio', 'changeNumber', 'deleGoods']),
    delGoods (e) {
      // console.log(e)
      this.deleGoods(e)
    },
    radioChange (goods) {
      // console.log(goods)
      this.changeRadio(goods)
    },
    numberChange (goods) {
      // console.log(goods)
      this.changeNumber(goods)
    }
  }
}
</script>

<style lang="scss" scoped>
.cart-container {
  padding-bottom: 50px;
  .cart-title {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    padding-left: 5px;
    border-bottom: 1px solid #efefef;
    .cart-title-text {
      margin-left: 10px;
    }
  }
}
.empty-cart {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 150px;

  .empty-img {
    width: 180rpx;
    height: 180rpx;
  }

  .tip-text {
    font-size: 12px;
    color: gray;
    margin-top: 15px;
  }
}
</style>
